"""IPAM数据模式."""

from typing import Optional

from pydantic import BaseModel, Field


class VRFBase(BaseModel):
    """VRF基础模式."""
    name: str = Field(..., description="VRF名称", max_length=100)
    rd: str = Field(..., description="Route Distinguisher", max_length=21)
    description: Optional[str] = Field(None, description="描述信息")


class VRFCreate(VRFBase):
    """VRF创建模式."""
    pass


class VRFResponse(VRFBase):
    """VRF响应模式."""
    id: int
    enforce_unique: bool
    
    class Config:
        from_attributes = True


class VLANBase(BaseModel):
    """VLAN基础模式."""
    vid: int = Field(..., description="VLAN ID", ge=1, le=4094)
    name: str = Field(..., description="VLAN名称", max_length=100)
    description: Optional[str] = Field(None, description="描述信息")


class VLANCreate(VLANBase):
    """VLAN创建模式."""
    pass


class VLANResponse(VLANBase):
    """VLAN响应模式."""
    id: int
    
    class Config:
        from_attributes = True


class IPNetworkBase(BaseModel):
    """IP网络基础模式."""
    network: str = Field(..., description="网络地址", max_length=43)
    prefix_length: int = Field(..., description="前缀长度", ge=1, le=128)
    description: Optional[str] = Field(None, description="描述信息")
    vrf_id: Optional[int] = Field(None, description="VRF ID")
    vlan_id: Optional[int] = Field(None, description="VLAN ID")


class IPNetworkCreate(IPNetworkBase):
    """IP网络创建模式."""
    pass


class IPNetworkResponse(IPNetworkBase):
    """IP网络响应模式."""
    id: int
    is_active: bool
    total_addresses: int
    used_addresses: int
    
    class Config:
        from_attributes = True


class IPAddressBase(BaseModel):
    """IP地址基础模式."""
    address: Optional[str] = Field(None, description="IP地址", max_length=39)
    network_id: int = Field(..., description="网络ID")
    hostname: Optional[str] = Field(None, description="主机名", max_length=255)
    description: Optional[str] = Field(None, description="描述信息")
    mac_address: Optional[str] = Field(None, description="MAC地址", max_length=17)


class IPAddressCreate(IPAddressBase):
    """IP地址创建模式."""
    pass


class IPAddressResponse(IPAddressBase):
    """IP地址响应模式."""
    id: int
    status: str
    created_at: str
    updated_at: str
    
    class Config:
        from_attributes = True